<?php

namespace app\common\model;
use think\Model;
use think\Db;

class Users extends Model {

    protected $insert = ['reg_time'];

    protected function initialize() {
        parent::initialize();
    }
    
     /* 注册 钩子函数 */
    protected static function init() {
        self::event('after_insert', function(&$data) {
            $data = $data->toArray();
            self::_after_insert($data);
        });
    }
    
    //新增之后的操作
    protected static function _after_insert(&$data) {
        if($data['password'])
            Db::name('Users')->where(['user_id' => $data['user_id']])->update(['password'=>md5($data['password'])]); //密码MD5       
    }

    

}
